package nc.bs.levmcardbd.readcardlog;

import java.util.ArrayList;
import java.util.List;

import nc.bs.framework.common.NCLocator;
import nc.bs.mmgp.dao.MMGPCmnDAO;
import nc.itf.levmcardbd.readcardlog.IReadCardLogService;
import nc.itf.mmgp.uif2.IMMGPCmnQueryService;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanProcessor;
import nc.uap.lfw.ra.util.ObjSelectedUtil;
import nc.vo.levmcardbd.readcardlog.ReadCardLogVO;
import nc.vo.mmgp.util.MMArrayUtil;
import nc.vo.pub.BusinessException;

public class ReadCardLogServiceImpl implements IReadCardLogService
{
  private IMMGPCmnQueryService queryService;
  
  private IUAPQueryBS queryBS;
  
  protected IUAPQueryBS getIUAPQueryBSServer()
  {
    if (queryBS == null) {
    	queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
    }
    
    return queryBS;
  }
  
  protected IMMGPCmnQueryService getQueryServer()
  {
    if (queryService == null) {
      queryService = ((IMMGPCmnQueryService)NCLocator.getInstance().lookup(IMMGPCmnQueryService.class));
    }
    
    return queryService;
  }
  
  public void saveCardLog(ReadCardLogVO[] vos)
    throws BusinessException
  {
    if (MMArrayUtil.isEmpty(vos)) {
      return;
    }
    MMGPCmnDAO dao = new MMGPCmnDAO();
    dao.insertVOArray(vos);
  }
  
  public ReadCardLogVO[] queryCardLogByCardID(String cardID) throws BusinessException
  {
//    Object[] objs = getQueryServer().cmnQueryDatasByCondition(ReadCardLogVO.class, " isnull(dr,0) = 0 and vcardid = '" + cardID + "' and READCARDTIME>to_char(sysdate-1,'YYYY-MM-DD hh24:mi:ss')");
//	if (MMArrayUtil.isEmpty(objs)) {
//      return null;
//    }
//    List<ReadCardLogVO> list = new ArrayList();
//    for (Object object : objs) {
//      list.add((ReadCardLogVO)object);
//    }
//	  return (ReadCardLogVO[])list.toArray(new ReadCardLogVO[0]);
	Object executeQuery = getIUAPQueryBSServer().executeQuery("select * from levm_readcardlog where nvl(dr,0)=0 and vcardid = '" + cardID + "' order by READCARDTIME desc", new BeanProcessor(ReadCardLogVO.class));
	if(executeQuery!=null){
		return new ReadCardLogVO[]{(ReadCardLogVO) executeQuery};
	}else{
		return null;
	}
    
  }
}
